Skip to content

Comments

Sourcery refactored main branch#1

Open
sourcery-ai[bot] wants to merge 1 commit intomainfrom
sourcery/main
Open

Sourcery refactored main branch#1
sourcery-ai[bot] wants to merge 1 commit intomainfrom
sourcery/main

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Dec 3, 2022

Branch main refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the main branch, then run:

git fetch origin sourcery/main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from Liftyee December 3, 2022 09:08
avgy += b.yc
bcount += 1

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found the following improvement in Function Boid.getavgpos:

Comment on lines -115 to +116

avgd = avgd/bcount
return avgd

return avgd/bcount
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Boid.getavgdir refactored with the following changes:

Comment on lines -121 to +123
if self.alone:
pygame.draw.rect(screen, (0, 0, 255), (ax%width, ay%height, 5, 5))
else:
pygame.draw.rect(screen, (0, 0, 255), (ax%width, ay%height, 5, 5)) # just draws a rectangle at where the average position is
pygame.draw.rect(screen, (0, 0, 255), (ax%width, ay%height, 5, 5))
relx = ax - self.x
rely = ay - self.y

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Boid.cohesion refactored with the following changes:

This removes the following comments ( why? ):

# just draws a rectangle at where the average position is

Comment on lines -147 to -155
if rx > 0 and ry > 0:

if rx > 0 and ry > 0 or (rx <= 0 or ry >= 0) and (rx >= 0 or ry >= 0):
self.rot += tcs
elif rx > 0 and ry < 0:
self.rot -= tcs
elif rx < 0 and ry < 0:
self.rot -= tcs
else:
self.rot += tcs
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Boid.separate refactored with the following changes:

Comment on lines -209 to 211

boids = []
boids = [
Boid(
randint(0, width),
randint(0, height),
pygame.image.load("boid.png"),
150,
)
for _ in range(100)
]


Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 209-224 refactored with the following changes:

This removes the following comments ( why? ):

# add boids

avgy += b.y
bcount += 1

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found the following improvement in Function Boid.getavgpos:

Comment on lines -120 to +125
boids = []
boid = Boid(100, 100, pygame.image.load("boid.png"))

boids.append(Boid(randint(500, 1000), randint(500, 1000), pygame.image.load("boid.png")))
boids = [
Boid(randint(500, 1000), randint(500, 1000), pygame.image.load("boid.png"))
]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 120-134 refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Dec 3, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.92%.

Quality metrics Before After Change
Complexity 3.26 ⭐ 2.91 ⭐ -0.35 👍
Method Length 59.52 ⭐ 57.97 ⭐ -1.55 👍
Working memory 6.69 🙂 6.66 🙂 -0.03 👍
Quality 76.24% 77.16% 0.92% 👍
Other metrics Before After Change
Lines 291 291 0
Changed files Quality Before Quality After Quality Change
boids/boids.py 74.57% 🙂 75.76% ⭐ 1.19% 👍
boids/boidtest.py 79.19% ⭐ 79.55% ⭐ 0.36% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
boids/boids.py Boid.move 3 ⭐ 123 😞 8 🙂 67.29% 🙂 Try splitting into smaller methods
boids/boids.py Boid.__init__ 0 ⭐ 106 🙂 10 😞 68.19% 🙂 Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants